pub use sea_orm::entity::prelude::*;
use sea_orm::sea_query::ForeignKeyAction;

use super::auth;

#[derive(Debug, Clone, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "user_admin")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i64,
    #[sea_orm(unique)]
    pub auth_id: i64,
}

#[derive(Debug, Clone, Copy, EnumIter)]
pub enum Relation {
    Auth,
}

impl RelationTrait for Relation {
    fn def(&self) -> RelationDef {
        match self {
            Relation::Auth => Entity::belongs_to(auth::Entity)
                .from(Column::AuthId)
                .to(auth::Column::Id)
                .on_delete(ForeignKeyAction::Cascade)
                .on_update(ForeignKeyAction::Cascade)
                .into(),
        }
    }
}

crate::add_relate! {
    auth::Entity => Entity | Relation::Auth
}

impl ActiveModelBehavior for ActiveModel {}
